package com.atguigu.tingshu.album.mapper;

import com.atguigu.tingshu.model.album.AlbumStat;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface AlbumStatMapper extends BaseMapper<AlbumStat> {

    @Select("select\n" +
            "    stat.album_id,\n" +
            "    MAX(IF(stat.stat_type = '0701', stat.stat_num, 0))   as playStatNum,\n" +
            "    MAX(IF(stat.stat_type = '0702', stat.stat_num, 0))   as collectStatNum,\n" +
            "    MAX(IF(stat.stat_type = '0703', stat.stat_num, 0))   as praiseStatNum,\n" +
            "    MAX(IF(stat.stat_type = '0704', stat.stat_num, 0))   as commentStatNum\n" +
            "from album_stat stat\n" +
            "where stat.album_id = #{albumId}\n" +
            "group by stat.album_id")
    AlbumStatVo selectAlbumStatVo(@Param("albumId") Long albumId);
}
